import { getApplyPolicyFormList } from "@/network/policy/service";
import { setToken } from "@/utils/login/ssoLogin";
import { Component } from "react";
import { Props, State } from "./model";
export default class Service extends Component<Props,State>{
   

    constructor(props:Props){
        super(props)
    }


    state: Readonly<State>={
        formList:{},
        formsModelsValue:{}
    }






    setApplyPolicyFormList = async()=>{
        try {
            const {state:{policy_id}}=this.props.history.location;
            const currentArea=JSON.parse(localStorage.getItem("currentArea") as string);
            const data=await getApplyPolicyFormList({
                areaId:currentArea?.key,
                 id:policy_id,
                 from:"",
            })

            if(data.bigFormsModel) {
                alert("该业务复杂，请到电脑端进行办理！");
                this.props.history.push("index")
                return;
            }

            data.formsModels.map((item:any,index:number)=>{
                this.state.formsModelsValue[item.name]=item.defaultValue
            })

            this.setState({formList:data},()=>{
                return
            })
        } catch (error) {
            console.log(error)
        }
    }
   
    
    

    componentWillMount=async()=>{
        setToken("personalToken");
        this.setApplyPolicyFormList();
    }


}